package com.milotnt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.milotnt.mapper.ProductMapper;
import com.milotnt.pojo.productEntity;
import com.milotnt.service.ProductService;
import com.milotnt.vo.ProductVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
@Transactional
public class ProductServiceImpl extends ServiceImpl<ProductMapper, productEntity> implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<ProductVo> findAllProducts() {
        return productMapper.findAllProducts();
    }

    @Override
    public Boolean insertProduct(productEntity product) {
        Date date = new Date();
        product.setCreateTime(date);
        return productMapper.insertProduct(product);
    }

    @Override
    public Boolean deleteByProductId(Long productId) {
        return productMapper.deleteByProductId(productId);
    }

    @Override
    public List<ProductVo> selectByProductId(Long productId) {
        return productMapper.selectByProductId(productId);
    }

    @Override
    public Boolean updateProductByProductId(productEntity product) {
        Date date = new Date();
        product.setUpdateTime(date);
        return productMapper.updateProductByProductId(product);
    }

    @Override
    public Integer selectTotalCount() {
        return productMapper.selectTotalCount();
    }

}
